package br.unirio.brasileirao.dao.mysql;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class BaseDaoMysql 
{
	protected Connection conn;
	
	public BaseDaoMysql( Connection conn )
	{
		this.conn = conn;
	}
	
	//-------------------------------------------------------------------------
	protected void close( Statement stmt ) throws SQLException
	{
		if( stmt != null )
			stmt.close();
	}

	//-------------------------------------------------------------------------
	protected void close( ResultSet rs ) throws SQLException
	{
		if( rs != null )
			rs.close();
	}
	
    //-------------------------------------------------------------------------
    protected Integer getInteger( ResultSet rs, String nomeColuna ) 
    	throws SQLException
    {
        int value = rs.getInt( nomeColuna );
        return rs.wasNull() ? null : value;
    }
    
    //-------------------------------------------------------------------------
	protected void insereIntNull( CallableStatement cs, String nomeParm, Integer value ) 
		throws SQLException 
	{
		if( value != null )
			cs.setInt( nomeParm, value );
		else
			cs.setNull( nomeParm, java.sql.Types.INTEGER );
	}
}
